<?php
session_start();
if (isset($_SESSION['userid']) && $_SESSION['level']!=2)
{
	header ("location: login.php");
	exit();
}

?>
<?php
include("includes/top_user.php");
?>

<?php
include("includes/connect.php");
$id=$_GET['threadid'];
$sql="select thread.id, title, content, username from thread,user where thread.user_id=user.id and thread.id='".$id."' ";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
if(isset($_POST['ok']))
{
	
	if($_POST['tb_title'] == "") { echo "Please enter your title"; }
	else{ $t = $_POST['tb_title']; }
	if($_POST['tb_content'] == "") { echo "Please enter your content"; }
	else{ $c = $_POST['tb_content']; }
	if($_POST['tb_author'] == "") { echo "Please enter the author"; }
	else{ $a = $_POST['tb_author']; }
	if($t!="" && $c!="" && $a!="")
	{
		$sql = "update thread set title='".$t."', content='".$c."', user_id='".$a."' where thread.id='".$id."'";
		mysql_query($sql);
		header("location: thread_manager.php");
		exit();
 	}
}

?>
<div id="box">
<h3>Quản lý bài viết</h3>
<form class="fr_manage_thread" name="fr_manage_thread" action="edit_thread.php?threadid=<?=$id?>" method="post">
    
    Mã bài viết : <input type="text" name="tb_id" size="20" value="<?=$row['id']?>"  /> <br />
    Tiêu đề : <input type="text" name="tb_title"  value="<?=$row['title']?>"  /> <br />
    Nội Dung : <textarea class="ckeditor" name="tb_content" rows="70" cols="30" value="<?=$row['content']?>"></textarea> <br />
    Tác giả : <input type="text" name="tb_author" size="39" value="<?=$row['username']?>"  /> <br />
    <input type="submit" name="ok" value="Cập Nhật"  />
        
</form>

</div><!--box-->

<?
include("includes/sidebar.php");
include("includes/footer.php");
?>

